#pragma once

#include <iostream>
#include <memory>
#include <unordered_map>
#include "Logger.hpp"

class Session
{
public:
    using ptr = std::shared_ptr<Session>;
    Session();
    Session(std::string username, std::string password, int status, uint64_t login_time);
    ~Session();

private:
    std::string username;
    std::string password;
    int status;
    uint64_t login_time; // 时刻
    // 等等阶段信息、参数
};

class SessionManager
{
public:
    SessionManager(){}
    ~SessionManager(){}

    std::string AddSession(std::string username, std::string password, int status, uint64_t login_time)
    {
        std::string session_id = username + std::to_string(login_time);
        sessions[session_id] = std::make_shared<Session>(username, password, status, login_time);
        return session_id;
    }

    void DelSession(std::string& session_id)
    {
        if(sessions.find(session_id) == sessions.end()) {
            DLOG("session_id not found\n");
        }
        
        sessions.erase(session_id);
        // return true;
    }

    void ModifySession(std::string& session_id, Session::ptr session)
    {
        if(sessions.find(session_id) == sessions.end()) {
            DLOG("session_id not found\n");
            return ;
        }

        sessions[session_id] = session;
    }

private:
    std::unordered_map<std::string, Session::ptr> sessions;
};